#pragma once

#include "Item.h"
#include "ofMain.h"
#include "Resources.h"

#include <map>

using namespace std;

class Player;

/** Enum to store all possible block colors. Retrievable in 0xRRGGBB format. **/
enum BLOCKCOLORS {
    BLOCKCOLOR_DIRT = 0x79553a,
    BLOCKCOLOR_STONE = 0x7f7f7f,
    BLOCKCOLOR_BEDROCK = 0x575757
};

/** A placeable world object. Generally, anything you can build with. **/
class Block : public Item
{
public:
    /** Constructor.
        \param x x position of the block
        \param y y position of the block
        \param ID ID of the block being created
        \param transparent true if the block should be transparent **/
    Block(int x, int y, int item = 0, bool transparent = false);

    /** Event Class for activating a block **/
    class BlockActivationEvent {
    public:
        BlockActivationEvent(Player *sender, int tool = 0, char side = 'U') :
            tool(tool), side(side), sender(sender) {}
        int  tool;
        char side;
        Player *sender;
    };

    /** Registers a hit with a block from a given tool.
        \param tool the item currently being used to whack the block
        \return true if destroyed, false otherwise. **/
    virtual bool destroy(Item *tool);
    /** Notifies the block that it is being activated.
        \param tool the item that the block is being activated with **/
    virtual void activate(BlockActivationEvent e);
    /** Gets the current damage value of the block.
        \return 0.0f to 1.0f, where 1.0f is fully destroyed **/
    virtual float damageValue();

    /** Draws the block at its current position. **/
    void draw();

    /** Stops hitting a block, resets damage value. **/
    void stopHitting();

    const bool transparent; /**< True if object can be walked through **/

protected:
    /** Releases a block to the environment. **/
    virtual void releaseBlock();
    virtual void releaseBlockByID(int ID);

    /** Attempts to get the approximate RGB color of the block.
        \return decimal integer in 0xRRGGBB format **/
    int getColor();

    float dmg;          /**< Current damage value from 0.0f (untouched) - 1.0f (destroyed) **/
    float lastHit;      /**< Time (in seconds) where the block was last hit **/
    bool  isBeingHit;   /**< True if block is in process of being destroyed **/
    const int x,        /**< X-Coordinate of the block **/
              y;        /**< Y-Coordinate of the block **/

    map<int, float> dmgRates; /**< table correlating damage rates by different tools on the block **/
};
